﻿using System;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Localization;
using Christoc.Modules.CouponsDiscounts.Components;
using System.Web.UI.WebControls;
using System.Data;
using Christoc.Modules.CouponsDiscounts.Data;
using Christoc.Modules.CouponsDiscounts.Components.Controllers;
using DotNetNuke.Services.Localization;

namespace Christoc.Modules.CouponsDiscounts
{
    public partial class ListProducts : CouponsDiscountsModuleBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetProducts();
            }
        }

        private void GetProducts()
        {
            listProducts.DataSource = Christoc.Modules.CouponsDiscounts.Components.Controllers.ProductSaleController.GetProducts();
            listProducts.DataBind();
        }

        protected void lnkBuy_Click(object sender, EventArgs e)
        {
            string idProduct = ((LinkButton)sender).CommandName;

            string script = EditUrl(String.Empty, String.Empty, "Buy", "idProduct=" + idProduct);
            script = script.Replace("550", "250");
            script = script.Replace("950", "250");

            Page.ClientScript.RegisterStartupScript(this.GetType(), "buyProduct", "<script type='text/javascript'> " + script + ";</script>");
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "buyProduct", "<script type='text/javascript'> dnnModal.show('~/DetailsBuy2.ascx?idProduct=" + idProduct + "&popup=true' ,/*showReturn*/false,250,250,true,'');</script>");
        }
    }
}